let users = [
    {
        id: 1,
        username: 'admin',
        password: '113',
        nickname: '小小黎',
        avatar: '这是一个头像'
    },
    {
        id: 2,
        username: 'li111',
        password: '113',
        nickname: '小小黎',
        avatar: '这是一个头像'
    },
    {
        id: 3,
        username: 'li222',
        password: '113',
        nickname: '小小黎',
        avatar: '这是一个头像'
    },
    {
        id: 4,
        username: 'li333',
        password: '113',
        nickname: '小小黎',
        avatar: '这是一个头像'
    }
];

let fn_index = (ctx, next) => {
    ctx.body = '我可能不是一个首页=_=|||';
}

let fn_about = (ctx, next) => {
    ctx.body = '关于我，关于你，关于你我。。。'
}

let fn_ok = (ctx, next) => {
    ctx.body = '我是post'
}

let fn_login = (ctx, next) => {
    let username = ctx.request.body.username || ''
    let password = ctx.request.body.password || ''
    let list = users.filter(item => {
        return item.username === username && item.password === password;
    })
    let res;
    if (list.length > 0) {
        ctx.body = {
            code: 1000,
            data: list[0],
            msg: '登录成功'
        };
    } else {
        ctx.body = {
            code: 400,
            data: '',
            msg: '用户名或密码错误，请确认后重试'
        };
    }


}


module.exports = {
    'get /': fn_index,
    'post /': fn_ok,
    'get /about': fn_about,
    'post /login': fn_login
}